package com.epam.facebook_client.processor;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.epam.facebook_client.content.contract.AppContract;
import com.epam.facebook_client.parser.FbJsonParser;
import com.epam.facebook_client.wrapper.Feed;

public class FeedsProcessor extends AbstractProcessor {

	public static final String ACTION = "action_feeds";
	protected static final String TAG = FeedsProcessor.class.getSimpleName();

	public FeedsProcessor(Context context) {
		super(context);
	}

	@Override
	public Bundle executeGet(Intent intent) throws Exception {
		String url = intent.getStringExtra(EXTRA_URL);

		FbJsonParser parser = new FbJsonParser(getContext());
		writeInDB(url, parser);
		
		Feed localFeed = new Feed(parser.getJson());
		String nextPageUrl = localFeed.getNext();
		Bundle bundle = new Bundle();
		bundle.putString(EXTRA_URL, nextPageUrl);
		return bundle;
	}


	public Bundle executeDelete(final Intent intent) throws Exception {
		getContext().getContentResolver().delete(getUri(), null, null);
		return executeGet(intent);
	}

	@Override
	public Bundle executePost(Intent intent) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Uri getUri() {
		return AppContract.FeedColumns.CONTENT_URI;
	}
}
